﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;

using DevTeamIT;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Araclar
{
    public partial class _ExceptionInfo : XForm
    {
        string message = "";
        string trace = "";
        int exceptionId = -1;

        public _ExceptionInfo(int ExceptionId, string exceptionMessage, string trace)
        {
            InitializeComponent();
            this.Text += "- " + ExceptionId.ToString();
            message = exceptionMessage;
            exceptionId = ExceptionId;
            this.trace = trace;
        }

        string Konu = "ConfExpert - Hata Kodu: ";
        string welcome = "Hata içeriği dışında bize iletmek istediklerinizi buraya yazabilirsiniz.";
        private void ExceptionInfo_Load(object sender, EventArgs e)
        {
            labelControl2.Text = message;
            //labelControl2.MaximumSize = new System.Drawing.Size(245, 200);
            labelControl2.AutoSizeMode = LabelAutoSizeMode.Vertical;

            Konu += exceptionId.ToString();
            txtIcerik.Text = welcome;
            this.Shown += ExceptionInfo_Shown;
        }

        void ExceptionInfo_Shown(object sender, EventArgs e)
        {
            txtIcerik.Focus();
            txtIcerik.ScrollToCaret();
        }

        private void btnBildir2_Click(object sender, EventArgs e)
        {
            try
            {
                string icerik = "<span style='font-family:verdana'>" + txtIcerik.Text +
                                "<p><b>Gönderen:</b>" + Session.CurrentUser.Name + "</b>" +
                                "<p><b>İlgili:" + Session.CurrentUser.Email + "</b>" +
                                "<p><b>Exception:" + message + "</b>" +
                                "<p><b>Trace:" + trace + "</b>";

                icerik = txtIcerik.Text.Replace(welcome, string.Empty); // +"|Trace:" + trace;

                Session.DataManager.ExecuteNonQuery("ExceptionBildir", exceptionId, icerik);

                //ceMessenger.ceMessengerSoapClient messenger = new ceMessenger.ceMessengerSoapClient();
                //messenger.Endpoint.Address = new System.ServiceModel.EndpointAddress(string.Format("http://{0}/ceMessenger/ceMessenger.asmx", Session.ServerAddress));
                //messenger.SendEmail("ce", "ce", "ConfExpert - Hata", "software@karbel.com", Konu, icerik , "");

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                //XtraMessageBox.Show("Bağlantı hatası! Lütfen önce ağ/internet bağlantınızı kontrol edin.", "Sistem Hatası");
                XtraMessageBox.Show("Lütfen hata kodu ile software@karbel.com adresine e-posta gönderin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
